package com.zzzyh.bookbackgroundsystem.controller;

import com.zzzyh.bookbackgroundsystem.constant.Constants;
import com.zzzyh.bookbackgroundsystem.service.UserService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    UserService userService;
    @RequestMapping("/login")
    public Boolean login(String username, String password, HttpSession session){
        if(!StringUtils.hasLength(username) || !StringUtils.hasLength(password)){
            return false;
        }
        if(userService.login(username,password)){
            session.setAttribute(Constants.USER_SESSION_KEY,username);
            return true;
        }
        return false;
    }
}
